package com.bhudy.utils;


import com.bhudy.exception.SysExceptionCode;

/**
 * @Author com.bhudy
 * @Description 处理成功返回给页面的类
 * @Date 2019-10-30 23:09:37
 */
public final class ResponseResult {

    public ResponseResult(int code, Long count, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
        this.count = count;
    }

    private int code;
    private Long count;
    private String message;
    private Object data;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public Long getCount() {
        return count;
    }

    public void setCount(Long count) {
        this.count = count;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public static ResponseResult printMapJson() {
        return ResponseResult.printMapJson(0, null, null, null);
    }

    /**
     * 根据code返回json数据
     */
    public static ResponseResult printMapJson(Object data) {
        return ResponseResult.printMapJson(0, null, null, data);
    }

    /**
     * 根据code返回json数据
     */
    public static ResponseResult printMapJson(String msg, Object data) {
        return ResponseResult.printMapJson(0, null, msg, data);
    }

    /**
     * 根据code返回json数据
     */
    public static ResponseResult printMapJson(int code, Object data) {
        return ResponseResult.printMapJson(code, null, null, data);
    }

    /**
     * 根据code返回json数据
     */
    public static ResponseResult printMapJson(int code, int count, Object data) {
        return ResponseResult.printMapJson(code, (long) count, null, data);
    }

    /**
     * 根据code返回json数据
     */
    public static ResponseResult printMapJson(int code, long count, Object data) {
        return ResponseResult.printMapJson(code, count, null, data);
    }

    /**
     * 根据code返回json数据
     */
    public static ResponseResult printMapJson(int code, Long count, String msg, Object data) {
        /*HttpServletResponse resp = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse();
        resp.setContentType("text/json; charset=UTF-8");*/

        if (msg == null) {
            msg = SysExceptionCode.getMessage(code);
        }

        /*Map<String, Object> map = new HashMap<>();
        map.put("code", code);
        map.put("message", msg);
        map.put("data", data);
        if (count != null) {
            map.put("count", count);
        }*/

        return new ResponseResult(code, count, msg, data);
        // return JSON.toJSONString(map, SerializerFeature.WriteMapNullValue, SerializerFeature.DisableCircularReferenceDetect);
    }

}